import { defineStore } from 'pinia';
import { Api } from '../script/Api'

const empty = {
  tbUser: {},
  tbUserInfo: {},
  userPwd: {},
  tbRole: {},
  exInfo: {},
}
export const store = defineStore('user',{
  state() {
    return {
      user: empty,
      isLogin: false,
    }
  },
  actions: {
    update(cb) {
      let instance = this;
      Api.get('/auth',{},(data) => {
        if(data.success){
          instance.user = data.data;
          instance.isLogin = true;
        } else {
          instance.user = empty;
          instance.isLogin = false;
        }
        cb?.(data.success);
      });
    },
  },
});

export default store;
